package com.mes.biz.service.impl;

import java.util.List;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.domain.BaseEntity;
import com.mes.common.core.service.BaseServiceImpl;
import com.mes.biz.mapper.BizSupplierMapper;
import com.mes.biz.domain.BizSupplier;
import com.mes.biz.service.BizSupplierService;
import org.springframework.transaction.annotation.Transactional;
import com.mes.common.exception.BizException;
import org.springframework.util.CollectionUtils;

/**
 * 供应商档案Service业务层处理
 * @author hwg
 * @email hwg
 * @date 2023-04-30
 */
@Service
@Transactional(readOnly = true)
public class BizSupplierServiceImpl extends BaseServiceImpl<BizSupplierMapper, BizSupplier> implements BizSupplierService {

    private static final Logger log = LoggerFactory.getLogger(BizSupplierServiceImpl.class);

    /**
     * 获取单条数据
     * @param bizSupplier 供应商档案
     * @return 供应商档案
     */
    @Override
    public BizSupplier get(BizSupplier bizSupplier) {
        BizSupplier dto = super.get(bizSupplier);
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 供应商档案id
     * @return 供应商档案
     */
    @Override
    public BizSupplier get(String id) {
        BizSupplier dto = super.get(id);
        return dto;
    }

    /**
     * 查询供应商档案列表
     * @param bizSupplier 供应商档案
     * @return 供应商档案
     */
    @Override
    public List<BizSupplier> findList(BizSupplier bizSupplier) {
		List<BizSupplier> bizSupplierList = super.findList(bizSupplier);
        return bizSupplierList;
    }

    /**
     * 分页查询供应商档案列表
     * @param bizSupplier 供应商档案
     * @return 供应商档案
     */
    @Override
    public PageInfo<BizSupplier> findPage(BizSupplier bizSupplier) {
		PageInfo<BizSupplier> page = super.findPage(bizSupplier);
        return page;
    }

    /**
     * 保存供应商档案
     * @param bizSupplier
     * @return 结果
     */
    @Override
    public boolean save(BizSupplier bizSupplier) {
        checkSupplierNameUnique(bizSupplier);
        return super.save(bizSupplier);
    }

    /**
     * 校验供应商名称的唯一性
     * @param bizSupplier
     */
    @Override
    public void checkSupplierNameUnique(BizSupplier bizSupplier) {
        BizSupplier bizSupplierUnique = new BizSupplier();
        bizSupplierUnique.setNotEqualId(bizSupplier.getId());
        bizSupplierUnique.setSupplierName(bizSupplier.getSupplierName());
        if (!CollectionUtils.isEmpty(mapper.findListWithUnique(bizSupplierUnique))) {
            throw new BizException("供应商名称已存在，请重新输入！");
        }
    }

    /**
     * 删除供应商档案信息
     * @param bizSupplier
     * @return 结果
     */
    @Override
    public boolean remove(BizSupplier bizSupplier) {
        return super.remove(bizSupplier);
    }

    /**
     * 批量删除供应商档案
     * @param ids 需要删除的供应商档案ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteBizSupplierByIds(String[] ids) {
        return mapper.deleteBizSupplierByIds(ids, BaseEntity.DEL_FLAG_DELETE);
    }

    @Override
    public BizSupplier getByCode(String supplierCode) {
        return mapper.getBizSupplierBySupplierCode(supplierCode);
    }

}
